package cn.wolfcode.luowowo.controller;

import cn.wolfcode.luowowo.domain.*;
import cn.wolfcode.luowowo.service.*;
import cn.wolfcode.luowowo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("destinations")
public class DestinationsController {
    @Autowired
    private IRegionService regionService;

    @Autowired
    private IDestinationService destinationService;

    @Autowired
    private IStrategyCatalogService strategyCatalogService;

    @Autowired
    private IStrategyService strategyService;

    @Autowired
    private ITravelService travelService;

    @GetMapping("/hotRegion")
    public Object hotRegion() {
        List<Region> regions = regionService.listAll();
        return JsonResult.success(regions);
    }

    @GetMapping("/search")
    public Object search(String regionId) {
        List<Destination> destinations = destinationService.search(regionId);
        return JsonResult.success(destinations);
    }

    @GetMapping("/toasts")
    public Object toasts(String destId) {
        List<Destination> toasts = destinationService.findByParentId(destId);
        return JsonResult.success(toasts);
    }

    @GetMapping("/detail")
    public Object detail(String id) {
        Destination destination = destinationService.select(id);
        return JsonResult.success(destination);
    }

    @GetMapping("/catalogs")
    public Object catalogs(String destId) {
        List<StrategyCatalog> list = strategyCatalogService.queryByDestId(destId);
        return JsonResult.success(list);
    }

    @GetMapping("/strategies/viewnumTop3")
    public Object strategiesViewnumTop3(String destId) {
        if (StringUtils.hasLength(destId)) {
            List<Strategy> strategies = strategyService.getViewnumTop3(destId);
            return JsonResult.success(strategies);
        } else {
            return JsonResult.success();
        }

    }

    @GetMapping("/travels/viewnumTop3")
    public Object travelsViewnumTop3(String destId) {
        if (StringUtils.hasLength(destId)) {
            List<Travel> travels = travelService.getViewnumTop3(destId);
            return JsonResult.success(travels);
        } else {
            return JsonResult.success();
        }

    }
}
